import 'package:flutter/material.dart';

class DownloadDialog extends StatelessWidget {
  final String title;
  final String message;
  final Future<void> Function() onDownload;

  const DownloadDialog({
    required this.title,
    required this.message,
    required this.onDownload,
    super.key,
  });

  @override
  Widget build(BuildContext context) {
    return Dialog(
      shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
      child: Padding(
        padding: const EdgeInsets.all(16.0),
        child: FutureBuilder<void>(
          future: onDownload(),
          builder: (context, snapshot) {
            if (snapshot.connectionState == ConnectionState.waiting) {
              return Column(
                mainAxisSize: MainAxisSize.min,
                children: [
                  const CircularProgressIndicator(),
                  const SizedBox(height: 16),
                  Text(title, style: const TextStyle(fontSize: 18)),
                  const SizedBox(height: 8),
                  Text(message, style: const TextStyle(color: Colors.grey)),
                ],
              );
            } else if (snapshot.hasError) {
              return Column(
                mainAxisSize: MainAxisSize.min,
                children: [
                  const Icon(Icons.error, color: Colors.red, size: 40),
                  const SizedBox(height: 16),
                  const Text("下载失败",
                      style: TextStyle(fontSize: 18, color: Colors.red)),
                  const SizedBox(height: 8),
                  Text(snapshot.error.toString(),
                      style: const TextStyle(color: Colors.grey)),
                  TextButton(
                    onPressed: () => Navigator.of(context).pop(),
                    child: const Text("关闭"),
                  ),
                ],
              );
            } else {
              return Column(
                mainAxisSize: MainAxisSize.min,
                children: [
                  const Icon(Icons.check_circle, color: Colors.green, size: 40),
                  const SizedBox(height: 16),
                  const Text("下载完成",
                      style: TextStyle(fontSize: 18, color: Colors.green)),
                  TextButton(
                    onPressed: () => Navigator.of(context).pop(),
                    child: const Text("关闭"),
                  ),
                ],
              );
            }
          },
        ),
      ),
    );
  }
}
